package com.tulingxueyuan.mall.modules.pms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mysql.cj.util.StringUtils;
import com.tulingxueyuan.mall.dto.BrandDTO;
import com.tulingxueyuan.mall.modules.pms.model.PmsBrand;
import com.tulingxueyuan.mall.modules.pms.mapper.PmsBrandMapper;
import com.tulingxueyuan.mall.modules.pms.service.PmsBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 品牌表 服务实现类
 * </p>
 *
 * @author Miao
 * @since 2022-05-19
 */
@Service
public class PmsBrandServiceImpl extends ServiceImpl<PmsBrandMapper, PmsBrand> implements PmsBrandService {

    /**
     * 商品品牌信息
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Page list(Long pageNum, Long pageSize,String keyword) {
        Page page=new Page<>(pageNum,pageSize);
        QueryWrapper<PmsBrand> queryWrapper=new QueryWrapper<>();

        if(!StringUtils.isNullOrEmpty(keyword)){
            queryWrapper.lambda().like(PmsBrand::getName,keyword);
        }

        queryWrapper.lambda().orderByAsc(PmsBrand::getSort);
        return this.page(page,queryWrapper);
    }

    /**
     * 状态更新
     * @param brandDTO
     * @return
     */
    @Override
    public boolean updateStatus(BrandDTO brandDTO) {
        UpdateWrapper<PmsBrand> updateWrapper=new UpdateWrapper<>();
        updateWrapper.lambda().set(PmsBrand::getFactoryStatus,brandDTO.getFactoryStatus())
                .in(PmsBrand::getId,brandDTO.getIds());
        boolean result=this.update(updateWrapper);
        return result;
    }

    @Override
    public boolean updateShowStatus(BrandDTO brandDTO) {
        UpdateWrapper<PmsBrand> updateWrapper=new UpdateWrapper<>();
        updateWrapper.lambda().set(PmsBrand::getShowStatus,brandDTO.getShowStatus())
                .in(PmsBrand::getId,brandDTO.getIds());
        boolean result=this.update(updateWrapper);
        return result;
    }
}
